//package com.example.uploadtest.hsf;
//
//import com.alibaba.nacos.api.NacosFactory;
//import com.alibaba.nacos.api.exception.NacosException;
//import com.alibaba.nacos.api.naming.NamingService;
//import com.alibaba.nacos.api.naming.pojo.Instance;
//import com.alibaba.nacos.api.naming.pojo.ListView;
//import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
//@Component
//public class NacosServicePrinter implements ApplicationRunner {
//    @Value("${spring.cloud.nacos.discovery.server-addr}")
//    private String serverAddr;
//    @Value("${spring.cloud.nacos.discovery.namespace}")
//    private String namespace;
//
//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        try {
//            // 创建 NamingService 实例
//            NamingService namingService = NacosFactory.createNamingService(serverAddr);
//            // 获取所有服务名
//            ServiceList serviceNamesList = namingService.getServicesOfServer(1, Integer.MAX_VALUE, namespace);
//            List<String> serviceNames = serviceNamesList.getData();
//            // 遍历每个服务并打印实例信息
//            for (String serviceName : serviceNames) {
//                System.out.println("\nService Name: " + serviceName);
//                ServiceInfo serviceInfo = namingService.getAllInstances(serviceName, namespace);
//                List<Instance> instances = serviceInfo.getHosts();
//                for (Instance instance : instances) {
//                    System.out.println("  Instance IP: " + instance.getIp() + ":" + instance.getPort());
//                    System.out.println("  Instance Metadata: " + instance.getMetadata());
//                }
//            }
//        } catch (NacosException e) {
//            System.err.println("Failed to fetch services from Nacos: " + e.getMessage());
//            e.printStackTrace();
//        }
//    }
//}
